/*
 * ParserParametros.c
 *
 */
#include "ParserParametros.h"


void convertirEntrada(int argc, char ** argv, char * op,char **f1,char **f2) {
	int opt = 0;
	int option_index = 0;
	static struct option long_options[] = {
			{ "help", no_argument, 0,'h' },
			{ "version", no_argument, 0, 'V' },
			{ "input", required_argument, 0, 'i' },
			{ "output", required_argument, 0, 'o' },
			{ "action", required_argument, 0, 'a' },
			{ 0, 0, 0, 0 }
	};

	*op = 'e';	
	while ((opt = getopt_long(argc, argv, "hVi:o:a:?", long_options, &option_index)) != -1) {
		switch (opt) {
			case 'h':
				mostrarMenu();
				break;
			case 'V':
				printf("Tp0 Organizacion de Computadoras \n\n");
				exit(0);
				break;
			case 'i':
				*f1 = optarg;
				break;
			case 'o':
				*f2 = optarg;
				break;
			case 'a':
				*op = optarg[0];
				break;
			case '?':
				fprintf(stderr, "Error - No existe la opcion: `%c'\n\n", optopt);
				exit(0);
				break;
			default:
				mostrarMenu();
				break;
		}
	}
}

void mostrarMenu() {

	printf("Usage:\n");
	printf("tp0 -h\n");
	printf("tp0 -V\n");
	printf("tp0 [options]\n");
	printf("Options:\n");
	printf("-V, --version\n");
	printf("Print version and quit.\n");
	printf("-h, --help\n");
	printf("Print this information.\n");
	printf("-i, --input\n");
	printf("Location of the input file.\n");
	printf("-o, --output\n");
	printf("Location of the output file.\n");
	printf("-a, --action\n");
	printf("Program action: encode (default) or decode.\n");
	printf("Examples:\n");
	printf("tp0 -a encode -i ~/input -o ~/output\n");
	printf("tp0 -a decode\n");

	exit(0);
}

